import type { Preferences, PreferencesType } from "../utils";

const links: Record<
	Exclude<
		| "ElysiaJS"
		| PreferencesType["linter"]
		| PreferencesType["orm"]
		| PreferencesType["plugins"][0]
		| PreferencesType["others"][0]
		| PreferencesType["database"],
		"None"
	>,
	string
> = {
	ElysiaJS: "[ElysiaJS](https://elysiajs.com/)",
	ESLint: "[ESLint](https://eslint.org/)",
	Biome: "[Biome](https://biomejs.dev/)",
	Prisma: "[Prisma](https://www.prisma.io/)",
	Drizzle: "[Drizzle](https://orm.drizzle.team/)",
	CORS: "[CORS](https://elysiajs.com/plugins/cors.html)",
	Swagger: "[Swagger](https://elysiajs.com/plugins/swagger.html)",
	JWT: "[JWT](https://elysiajs.com/plugins/jwt.html)",
	Autoload: "[Autoload](https://github.com/kravetsone/elysia-autoload)",
	Logger: "[Logger](https://github.com/bogeychan/elysia-logger)",
	"HTML/JSX": "[HTML/JSX](https://elysiajs.com/plugins/html.html)",
	Static: "[Static](https://elysiajs.com/plugins/static.html)",
	Bearer: "[Bearer](https://elysiajs.com/plugins/bearer.html)",
	"Server Timing":
		"[Server Timing](https://elysiajs.com/plugins/server-timing.html)",
	Husky: "[Husky](https://typicode.github.io/husky/)",
	PostgreSQL: "[PostgreSQL](https://www.postgresql.org/)",
	MySQL: "[MySQL](https://www.mysql.com/)",
	MongoDB: "[MongoDB](https://www.mongodb.com/)",
	SQLite: "[SQLite](https://sqlite.org/)",
	SQLServer: "[SQLServer](https://www.microsoft.com/sql-server)",
	CockroachDB: "[CockroachDB](https://www.cockroachlabs.com/)",
};

export function getReadme({
	dir,
	linter,
	orm,
	database,
	plugins,
	others,
}: Preferences) {
	const stack = [];

	stack.push(`- Web framework - ${links.ElysiaJS}`);
	if (linter !== "None") stack.push(`- Linter - ${links[linter]}`);
	if (orm !== "None") stack.push(`- ORM - ${links[orm]} (${links[database]})`);
	if (plugins.length)
		stack.push(`- Elysia plugins - ${plugins.map((x) => links[x]).join(", ")}`);
	if (others.length)
		stack.push(`- Others tools - ${others.map((x) => links[x]).join(", ")}`);

	return [
		`# ${dir}`,
		"",
		"This template autogenerated by [create-elysiajs](https://github.com/kravetsone/create-elysiajs)",
		"",
		"### Stack",
		...stack,
	].join("\n");
}
